// 观察者模式


// 定义observe
const queuedObservers = new Set()
const observe = fn => queuedObservers.add(fn)

// 定义observable
const observable = obj => new Proxy(obj, {
 set(target, key, value, receiver) {
  const result = Reflect.set(target, key, value, receiver)
  // notify 通知观察者
  queuedObservers.forEach(observer => observer())
  return result
 }
})

// 测试
obj = observable({
  name:'789'
})
observe(function test(){
  console.log('触发了')
})
 
obj.name ="前端柒⼋九"